﻿
//域名地址
document.write('<script src="js/configPath.js"></script>');

$(function () {

	$.ajax({
		type: "post",
		url: mdmPath + "/MDMCommonality/MDMCommonality01",
		data:   {
					"Content": {
				    	"CodeList": [
				      		"MDM0002"
				    	]
				  	}
				},
		dataType: "json",
		success: function(re){
			if(re.Status==200){
				var MDM0002 = re.Content.DropdownData.MDM0002;
				var options = '';
				for(var i in MDM0002){
					options += '<option value="'+i+'">'+MDM0002[i]+'</option>';
				}
				$("#loginDepartment").html(options);
			}else{
				alert(re.Message);
			}
		}
	});

	$("#submit").on('click', Getlogin);
	$("#username").on('focus', AlertHide);
	$("#password").on('focus', AlertHide);
	$("#loginDepartment").on('click', AlertHide);

	function Getlogin(){
		var ecode = $('#username').val();
	    var epwd = $('#password').val();
		params = { 
		    "BrowserID": "hhhh",	
		    "Content": {
		        "Code": ecode, 
		        "Ps": epwd
		    }
		}
	    if(ecode!=''&&epwd!=''){
		    //console.log(params)
		    var lsUrl = mdmPath+"/MDM0001/MDM000105";
		    $.ajax({
		        type: "post",
		        url: lsUrl,
		        data: params,
		        dataType: "json",
		        success: function(re) {
		            //alert(re.Status + re.Message);
		            if(re.Status==200){
		        		localStorage.setItem('Tonken',re.Tonken);
		        		localStorage.setItem('UserCode',re.UserCode);
		        		window.location.href = 'index.html';
		            }else{
		                AlertShow("登录失败，"+re.Message);
		            }
		        }
		    });
		}else{
		    AlertShow("登录失败，用户名或密码为空！");
		}
	}

	function AlertShow(text){
		$(".u_field .alert").show();
		$(".alert").text(text);
	}

	function AlertHide(){
		$(".u_field .alert").hide();
	}

})